package com.yc.dict.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yc.base.BaseServiceImpl;
import com.yc.dict.entity.Dict;
import com.yc.dict.mapper.DictMapper;
import com.yc.dict.service.IDictService;
import com.yc.enums.StatusEnum;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 后台字典表 服务实现类
 * </p>
 *
 * @author bao
 * @since 2021-12-10
 */
@RequiredArgsConstructor
@Service
public class DictServiceImpl extends BaseServiceImpl<DictMapper, Dict> implements IDictService {

    @Override
    public boolean create(Dict dict) {
        return save(dict);
    }

    @Override
    public boolean delete(List<Long> ids) {
        return removeByIds(ids);
    }

    @Override
    public boolean update(Dict dict) {
        return updateById(dict);
    }

    @Override
    public Dict queryById(Long id) {
        return getById(id);
    }

    @Override
    public Dict queryByName(String name) {
        QueryWrapper<Dict> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(Dict::getName, name).eq(Dict::getStatus, StatusEnum.NORMAL);
        return getOne(wrapper);
    }

    @Override
    public List<Dict> selectList() {
        QueryWrapper<Dict> wrapper = new QueryWrapper<>();
        wrapper.lambda().orderByDesc(Dict::getId);
        return list(wrapper);
    }

    @Override
    public IPage<Dict> selectPage(IPage<Dict> page) {
        QueryWrapper<Dict> wrapper = new QueryWrapper<>();
        wrapper.lambda().orderByDesc(Dict::getId);
        return page(page, wrapper);
    }
}
